package controllers;
import java.util.Map;

import models.entities.Staff;
import play.mvc.Http.Context;
import play.mvc.Result;
import play.mvc.Security.Authenticator;


public class Authentication extends Authenticator {

	@Override
	public String getUsername(Context context) {
		Map<String, Object> loginStaff = SessionManager.get("loginStaff");
		String staffCode = null;
		if(null != loginStaff) {
			Staff staff = (Staff) loginStaff.get("staff");
			staffCode = staff.getStaffCode();
		}
		return staffCode;
	}

	@Override
	public Result onUnauthorized(Context context) {
		return redirect("/login");
	}

}
